package com.yzd.learnjava.io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileLock;
import java.util.concurrent.TimeUnit;

import com.yzd.learnjava.util.Print;

public class FileLocking {
	public static void main(String[] args) throws Exception {
		FileOutputStream out = new FileOutputStream("file.txt");
		FileLock lock = out.getChannel().tryLock();
		if(lock != null) {
			Print.print("Flie Locked");
			TimeUnit.MICROSECONDS.sleep(100);
			lock.release();
			Print.print("Release Lock");
		}
		out.close();
	}
}
